import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { CommonService } from 'src/app/service/common/common.service';
import { FeeEnquiryService } from 'src/app/service/fee-enquiry/fee-enquiry.service';
import { ReportService } from 'src/app/service/fee-enquiry/report.service';
import { MessageService } from 'src/app/service/message.service';
import { UserInfoService } from 'src/app/service/user-info/user-info.service';

@Component({
  selector: 'app-baodu-list',
  templateUrl: './baodu-list.component.html',
  styleUrls: ['./baodu-list.component.scss']
})
export class BaoduListComponent implements OnInit {

  colNames = ['用户编号', '户名', '用水地址', '水表行度'];
  operates = [
    {key: '详情', router: '', param:{}},
  ];
  dataSet = [];

  constructor(
    private message: MessageService,
    private reportService: ReportService,
    private router: Router,
    private route: ActivatedRoute,
    private userInfo: UserInfoService,
    private feeEnquiry: FeeEnquiryService,
    private common: CommonService
  ) { }

  ngOnInit() {
    this.common.setRightInfoVisible(false)
    
    this.route.queryParams.subscribe((res: any) => {
      if(res && res.isDetail === 'false'){ // 工单查询 跳转到详情
        this._orderQuery(res.id);
      }else{ // 直接查询列表即可
        // this._getReportList();
      }
    })
  }

  // 工单查询的预览
  _orderQuery(id: string){
    this.router.navigate(['/fee-enquiry/baodu'], {queryParams: {id: id, isOrder: 'true'}})
  }

  handleBack(data: any){
    this.router.navigate(['/fee-enquiry/baodu'], {queryParams: {id: data.id, isOrder: 'false'}});
  }

  nzTableLoading = false;
  nzTotal = 0
  pageSize = 10
  pageNumber = 1
  _getReportList(){
    this.nzTableLoading = true;
    this.dataSet = []
    this.reportService.getReportList(this.pageNumber, this.pageSize).subscribe(res => {
      if(res){
        let resultList = res.resultList;
        this.nzTotal = res.totalNumber;
        let dataSet: any = []
        console.log(resultList)
        resultList.forEach((item: any) => {
          const data = {} as any
          data.id = item.id
          data.usageCode = item.usageCode
          data.name = item.name
          data.address = item.address
          data.meterNo = item.meterNo
          data.meterAddr = item.meterAddr
          data.num = item.num

          dataSet.push(data)
        })
        this.dataSet = dataSet;
      }else{
        this.nzTotal = 0;
      }
      this.nzTableLoading = false;
    }, error => {
      this.message.createErrorMessage(error);
      this.nzTableLoading = false;
    })
  }

  addClick(){
    
    this.router.navigate(['/fee-enquiry/baodu']);
  }
}
